// TelnetOption.h: interface for the CTelnetOption class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TELNETOPTION_H__CB3C13F4_7E07_4DB1_A9E8_DFB549100034__INCLUDED_)
#define AFX_TELNETOPTION_H__CB3C13F4_7E07_4DB1_A9E8_DFB549100034__INCLUDED_

#include "TelnetOptionEvents.h"
#include "ITelnetDataSender.h"
#include "TelnetConstsDef.h"

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

typedef enum
{
	NO = 0,
	WANTNO = 1,
	WANTYES = 2,
	YES = 3,
} enumOptionState;

typedef enum
{
	EMPTY = 0,
	OPPOSITE = 1,
} enumQueueBit;

class CTelnetOption  
{
protected:
	CTelnetOptionEvents *m_pEvents;
	virtual BOOL checkAgreeUsOn();
	virtual BOOL checkAgreeHimOn();
	
	virtual void OnUsChange();
	virtual void OnHimChange();

protected:
	ITelnetDataSender *m_pTelnetDataSender;
	void sendOptionCommand(char action);
	void sendDo();
	void sendDont();
	void sendWill();
	void sendWont();

protected:

	enumOptionState us;
	enumQueueBit usq;
	enumOptionState him;
	enumQueueBit himq;

public:
	const char OPTION_TYPE;
	BOOL IsUsOn();
	BOOL IsHimOn();

public:
	virtual void OnDo();
	virtual void OnDont();
	virtual void OnWill();
	virtual void OnWont();
	virtual void SetParameters(const char* buf, int bufLen);

	void RequestHimOn();
	void RequestHimOff();

	void RequestUsOn();
	void RequestUsOff();

	void RegisterEvents(CTelnetOptionEvents *pEvents);

public:
	CTelnetOption(ITelnetDataSender *pTelnetDataSender, char optionType, CTelnetOptionEvents *pEvents);
	virtual ~CTelnetOption();

};

#endif // !defined(AFX_TELNETOPTION_H__CB3C13F4_7E07_4DB1_A9E8_DFB549100034__INCLUDED_)
